package com.aionengine.gameserver.services.custom;

import com.aionengine.gameserver.model.gameobjects.LetterType;
import com.aionengine.gameserver.model.gameobjects.player.Player;
import com.aionengine.gameserver.services.abyss.AbyssPointsService;
import com.aionengine.gameserver.services.teleport.TeleportService2;
import com.aionengine.gameserver.skillengine.SkillEngine;
import com.aionengine.gameserver.skillengine.model.SkillTargetSlot;
import com.aionengine.gameserver.utils.PacketSendUtility;
import com.aionengine.gameserver.world.InstanceType;
import com.aionengine.gameserver.world.World;
import com.aionengine.gameserver.world.WorldMap;
import com.aionengine.gameserver.world.WorldMapInstance;
import com.aionengine.gameserver.world.WorldMapInstanceFactory;
import com.aionengine.gameserver.world.WorldMapType;
import com.aionengine.gameserver.services.mail.MailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author BlackCore
 */
public class NewbiePVP {
    
        private static final WorldMapType PVP_INSTANCE_MAP = WorldMapType.POETA;
	private static final int PVP_INSTANCE_ID = 99;
	
	private static final Logger log = LoggerFactory.getLogger(NewbiePVP.class);
        
        public synchronized static WorldMapInstance getPVPInstance() {
		WorldMap map = World.getInstance().getWorldMap(PVP_INSTANCE_MAP.getId());

		log.info("Creating new PVPinstance:" + PVP_INSTANCE_MAP + " id:" + PVP_INSTANCE_ID + " owner:" + 0);
		WorldMapInstance worldMapInstance = WorldMapInstanceFactory.createWorldMapInstance(map, PVP_INSTANCE_ID, 0, InstanceType.SOLO);
		map.addInstance(PVP_INSTANCE_ID, worldMapInstance);
          
		return worldMapInstance;
	}
        public static WorldMapInstance pvpInstance() {
		return World.getInstance().getWorldMap(PVP_INSTANCE_MAP.getId()).getWorldMapInstanceById(PVP_INSTANCE_ID);
	}
        
       public static boolean isInPVP(Player player) {
		return player.getPosition().getWorldMapInstance().isPVPSoloInstance();
                }
       
        public static void onEnter(Player p){
           if(isInPVP(p)){
               PacketSendUtility.sendYellowMessage(p,"Se inicia la sesion para los principiantes!");
           }
       }
       
       public static void onKill(Player killer, Player victim) {
		if (isInPVP(killer)) {
			killer.increacePVP2kills();
                        onReward(killer);       
			
		}
                
                 
                 }
        public static void onReward(Player killer) {
            int kills = killer.getPVP2kills();
            switch(kills){
                case 5:
                    PacketSendUtility.sendMessage(killer, "Usted ha cometido una serie de " +kills+ "  asesinatos");
                    break;
                case 10:
                    PacketSendUtility.sendMessage(killer, "Usted ha cometido una serie de " +kills+ "  asesinatos");
                    break;
                case 15:
                    PacketSendUtility.sendMessage(killer, "Usted ha cometido una serie de " +kills+ "  asesinatos");
                    break;
                default:
                    AbyssPointsService.addAp(killer, 1000);
                    PacketSendUtility.sendMessage(killer, "Recompensa estandar recompensa por matar.");
                    break;
            }
            if(kills==15){
                MailService.getInstance().sendMail(killer, "Lugar de principiantes", "Obtienes la recompensa por matar en JcJ ubicacion para los nuevos jugadores", "Gracias por jugar en nuestro servidor", 186000178, 5, 0, LetterType.NORMAL);
                killer.setPVP2kills(0);
                TeleportService2.teleportToCapital(killer);
            }
            
	}
	public static void onLogOut(Player player) {
		if (isInPVP(player)) {
			TeleportService2.teleportToCapital(player);
		}
	}
	
	public static void onRevive(Player player) {
		Teleport.teleportToPVP(player);
		player.getKnownList().doUpdate();
		player.getEffectController().removeAbnormalEffectsByTargetSlot(SkillTargetSlot.DEBUFF);
        SkillEngine.getInstance().applyEffectDirectly(18191, player, player, 5000);
        SkillEngine.getInstance().applyEffectDirectly(10380, player, player, 5000);
	}
        
        
    public static WorldMapType getPVPInstanceMap() {
		return PVP_INSTANCE_MAP;
	}
	
	public static int getPVPInstanceId() {
		return PVP_INSTANCE_ID;
	}
    
}
